package com.ocss.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ocss.system.domain.OcssStudent;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ocss.common.annotation.Log;
import com.ocss.common.core.controller.BaseController;
import com.ocss.common.core.domain.AjaxResult;
import com.ocss.common.enums.BusinessType;
import com.ocss.system.domain.OcssCourse;
import com.ocss.system.service.IOcssCourseService;
import com.ocss.common.utils.poi.ExcelUtil;
import com.ocss.common.core.page.TableDataInfo;

/**
 * 课程信息Controller
 *
 * @author ligen
 * @date 2024-03-06
 */
@RestController
@RequestMapping("/system/course")
public class OcssCourseController extends BaseController {
    @Autowired
    private IOcssCourseService ocssCourseService;

    /**
     * 查询课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(OcssCourse ocssCourse) {
        startPage();
        List<OcssCourse> list = ocssCourseService.selectOcssCourseList(ocssCourse);
        return getDataTable(list);
    }

    @GetMapping("/listDetail/{id}")
    public TableDataInfo courseDetailList(@PathVariable("id") Long id, OcssCourse ocssCourse) {
        startPage();
        List<OcssStudent> list = ocssCourseService.selectOcssCourseDetailList(ocssCourse, id);
        return getDataTable(list);
    }

    /**
     * 导出课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:course:export')")
    @Log(title = "课程信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OcssCourse ocssCourse) {
        List<OcssCourse> list = ocssCourseService.selectOcssCourseList(ocssCourse);
        ExcelUtil<OcssCourse> util = new ExcelUtil<OcssCourse>(OcssCourse.class);
        util.exportExcel(response, list, "课程信息数据");
    }

    /**
     * 获取课程信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:course:query') or @ss.hasPermi('system:course_selection:desc')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ocssCourseService.selectOcssCourseById(id));
    }

    /**
     * 新增课程信息
     */
    @PreAuthorize("@ss.hasPermi('system:course:add')")
    @Log(title = "课程信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OcssCourse ocssCourse) {
        return toAjax(ocssCourseService.insertOcssCourse(ocssCourse));
    }

    /**
     * 修改课程信息
     */
    @PreAuthorize("@ss.hasPermi('system:course:edit')")
    @Log(title = "课程信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OcssCourse ocssCourse) {
        return toAjax(ocssCourseService.updateOcssCourse(ocssCourse));
    }

    /**
     * 删除课程信息
     */
    @PreAuthorize("@ss.hasPermi('system:course:remove')")
    @Log(title = "课程信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ocssCourseService.deleteOcssCourseByIds(ids));
    }
}
